package com.ruoyi.framework.web.enums;


import com.ruoyi.framework.web.contants.AbnormalConstants;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 通用 异常 枚举
 *
 */
public class AbnormalEnum {

    @Getter
    @AllArgsConstructor
    public enum MSG {
        /**
         * 请求常规错误
         */
        UNKNOWN(10000, AbnormalConstants.UNKNOWN),
        /**
         * 服务器内部错误
         */
        DISCONNECTED(10001, AbnormalConstants.DISCONNECTED),
        /**
         * 请求权限不足
         */
        UNAUTHORIZED(10002, AbnormalConstants.UNAUTHORIZED),
        /**
         * 参数不合法
         */
        UNKNOWN_ORDER_COMPOSITION(10014, AbnormalConstants.UNKNOWN_ORDER_COMPOSITION),
        /**
         * 该服务不可用
         */
        SERVICE_SHUTTING_DOWN(10016, AbnormalConstants.SERVICE_SHUTTING_DOWN),
        /**
         * 不支持此操作
         */
        UNSUPPORTED_OPERATION(10020, AbnormalConstants.UNSUPPORTED_OPERATION),
        /**
         * 未发送强制性参数，该参数为空或格式错误
         */
        MANDATORY_PARAM_EMPTY_OR_MALFORMED(11002, AbnormalConstants.MANDATORY_PARAM_EMPTY_OR_MALFORMED),
        /**
         * 无效的交易币对
         */
        BAD_SYMBOL(11021, AbnormalConstants.BAD_SYMBOL),
        /**
         * 余额不足
         */
        BALANCE_NOT_SUFFICIENT(20005, AbnormalConstants.BALANCE_NOT_SUFFICIENT),
        /**
         * 用户找不到
         */
        OPTIONS_USER_NOT_FOUND(40032, AbnormalConstants.OPTIONS_USER_NOT_FOUND),
        /**
         * 创建支付订单失败
         */
        FAILED_TO_CREATE_PAYMENT_ORDER(40033, AbnormalConstants.FAILED_TO_CREATE_PAYMENT_ORDER),
        /**
         * 该地址已注册
         */
        THIS_ADDRESS_HAS_ALREADY_REGISTERED(40034, AbnormalConstants.THIS_ADDRESS_HAS_ALREADY_REGISTERED),
        /**
         * 该手机号已注册
         */
        THIS_PHONE_NUMBER_HAS_ALREADY_REGISTERED(40035, AbnormalConstants.THIS_PHONE_NUMBER_HAS_ALREADY_REGISTERED),
        /**
         * 账号或密码错误
         */
        INCORRECT_USERNAME_OR_PASSWORD(40036, AbnormalConstants.INCORRECT_USERNAME_OR_PASSWORD),
        /**
         * 创建提现申请失败
         */
        FAILED_TO_CREATE_WITHDRAWAL_REQUEST(40033, AbnormalConstants.FAILED_TO_CREATE_WITHDRAWAL_REQUEST),
        /**
         * 资金账户额度不足
         */
        INSUFFICIENT_FUND_ACCOUNT(40033, AbnormalConstants.INSUFFICIENT_FUND_ACCOUNT);

        private final int code;
        private final String message;

        /**
         * 根据name查找对应value
         *
         * @param code 枚举名称
         * @return java.lang.String
         * @since 1.0.0
         */
        public static String findMessage(int code) {
            for (MSG item : values()) {
                if (item.getCode() == code) {
                    return item.getMessage();
                }
            }

            return null;
        }

        /**
         * 根据value查找对应的name
         *
         * @param message 枚举值
         * @return java.lang.String
         * @since 1.0.0
         */
        public static int findCode(String message) {
            for (MSG item : values()) {
                if (item.getMessage().equals(message)) {
                    return item.getCode();
                }
            }
            return -1;
        }
    }
}
